package org.otarriinae.security.base.model;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;
import org.otarriinae.security.base.serialize.GrantedAuthorityDeserialize;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Map;

/**
 * @author xj
 * @since 1.0
 */

public class TokenUserDetails implements UserDetails {

    @Setter
    @Getter
    private Integer userId;

    @Setter
    private String username;

    /**
     * 密码不保存到redis中
     */
    @Setter
    @JSONField(serialize = false)
    private String password;

    @Setter
    @JSONField(deserializeUsing = GrantedAuthorityDeserialize.class)
    private Collection<? extends GrantedAuthority> authorities;

    @Setter
    @Getter
    private Map<Integer, String> categoryMap;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
